<html>

  <head>
    <meta charset="utf-8">
   <meta name="renderer" content="webkit|ie-comp|ie-stand" />  
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" type="text/css" href="layui/css/layui.css" media="all">
	<link rel="stylesheet" type="text/css" href="css/index.css"/>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=1e0u2fDgqYhUdilCb10Lz7xHyTBf99hG"></script>
    <title>选择地址</title>
    <style>
    	body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
    	#r-result{width:100%;position: absolute; top: 5%;}
    </style>
  </head>

  <body>
    <div class="pd-20 user-add">
      <div style="display: none;" id="allmap"></div>
      <div id="r-result">
      	请输入地址:<input type="text" id="suggestId" size="20" value="" style="width:150px; height: 28px;"/>
      	<a class="layui-btn btn-add btn-default" id="addmap" style="height: 28px; line-height: 28px;">确定</a>
      </div>
	  <div id="searchResultPanel" style="padding-top:60px; padding-left: 70px;"></div>
	
    </div>
    <script type="text/javascript" src="//cdn.bootcss.com/jquery/2.2.3/jquery.js"></script>
    <script src="layui/layui.js"></script>
    <script src="js/common.js"></script>
    <script type="text/javascript">
		// 百度地图API功能
		var map = new BMap.Map("allmap");
	layui.use(['layer','laydate'], function(){
		  var $ = layui.jquery;
		  var laydate = layui.laydate;
		  var url='http://api.map.baidu.com/highacciploc/v1?qterm=pc&ak=1e0u2fDgqYhUdilCb10Lz7xHyTBf99hG&coord=bd09ll&callback_type=jsonp&callback=test';
			$.ajax({
				url:url,
				dataType:'jsonp',
				processData: false, 
				type:'get',
				async : false,
				success:function(data){
					var x=data.content.location.lng;
					var y=data.content.location.lat;
					var marker = new BMap.Marker(new BMap.Point(x,y));  // 创建标注
					map.addOverlay(marker);   
					map.centerAndZoom(new BMap.Point(x,y), 11); // 初始化地图,设置中心点坐标和地图级别
					map.enableScrollWheelZoom(true);
					$('#suggestId').blur(function(){
						var val = $(this).val();
						var options = {
							onSearchComplete: function(results){
								//console.log(results)
								// 判断状态是否正确
								if (local.getStatus() == BMAP_STATUS_SUCCESS){
									var ul = '<ul>';
									for (var i = 0; i < results.getCurrentNumPois(); i ++){							
										
										ul += "<li style='width:400px; height:40px; margin:2px; border:1px solid #ccc' onclick='reply(this)'>" + results.getPoi(i).address+'-'+results.getPoi(i).title+"</li>";
									}
									ul += '</ul>';
									document.getElementById("searchResultPanel").innerHTML = ul;
								}
							}
						};
						var local = new BMap.LocalSearch(map, options);
							local.search(val);
					});
				},
			});
			
	});      
		
		function reply(dom){
			var index = parent.layer.getFrameIndex(window.name);
			parent.$("#deviceAddress").val($(dom).text());
			parent.layer.close(index);
		}
	</script>
  </body>

</html>